package com.shuker.design.factory.good.impl;

import com.alibaba.fastjson.JSON;
import com.shuker.design.coupon.CouponResult;
import com.shuker.design.coupon.CouponService;
import com.shuker.design.factory.good.store.ICommodity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author ：Shuker
 * @date ：Created in 2022/1/10 18:41
 * @description：优惠券发奖接口实现
 * @version: 1.0
 */
public class CouponCommodityService implements ICommodity {
    private Logger logger = LoggerFactory.getLogger(getClass());

    private CouponService couponService = new CouponService();

    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(uId,commodityId,bizId);
        logger.info("请求参数[优惠券]=>uid:{} commodityId: {} bizId: {} extMap: {}",uId,commodityId,bizId,extMap);
        logger.info("测试结果[优惠券]:{}", JSON.toJSON(couponResult));
        if(!"0000".equals(couponResult.getCode())){
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}
